package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.User;
import com.sxkf.template.entity.UserBlack;
import com.sxkf.template.service.UserBlackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户拉黑记录 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:58
 */
@Api(tags = "用户拉黑记录")
@RestController
@RequestMapping("/userBlack")
public class UserBlackController {
    @Resource
    private UserBlackService userBlackService;

    @ApiOperation(value = "查询拉黑用户")
    @GetMapping(value = "/page")
    public R<IPage<User>> page(@RequestParam Integer pageNo,
                               @RequestParam Integer pageSize,
                               @RequestParam Long userId){
        Page<UserBlack> page = userBlackService.page(new Page<>(pageNo, pageSize), new LambdaQueryWrapper<UserBlack>().eq(UserBlack::getUserId, userId));
        return R.success(userBlackService.handleResult(page));
    }

    @ApiOperation(value = "拉黑/取消拉黑")
    @PostMapping(value = "/add")
    public R<?> add(@RequestBody UserBlack userBlack){
        userBlackService.add(userBlack);
        return R.success();
    }

}
